<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">         
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
             <a-form-item label="户号">
              <a-input placeholder="请输入户号" v-model="queryParam.cusCode"></a-input>
            </a-form-item>           
          </a-col>
          
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>              
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

     <!-- table区域-begin -->
    <div>
      <!-- :pagination="ipagination" -->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">水量修改</a>

          <a-divider type="vertical" />          
        </span>
      </a-table>
    </div>

    <change-records-modal ref="modalForm" @ok="modalFormOk"></change-records-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { postAction } from '@api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import changeRecordsModal from './modules/changeRecordsModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'changeRecordsList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      changeRecordsModal
    },
    data () {
      return {
        description: '水量修改管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'抄表本',
            align:"center",
            dataIndex: 'bookId_dictText'
          },
          {
            title:'月份',
            align:"center",
            dataIndex: 'readMonth'
          },
          {
            title:'户号',
            align:"center",
            dataIndex: 'customerId'
          },
          {
            title:'户名',
            align:"center",
            dataIndex: 'cusName'
          },
          {
            title:'起度',
            align:"center",
            dataIndex: 'beginScale'
          },
          {
            title:'止度',
            align:"center",
            dataIndex: 'endScale'
          },
          {
            title:'用量',
            align:"center",
            dataIndex: 'amount'
          },
          // {
          //   title:'抄表周期',
          //   align:"center",
          //   dataIndex: 'waterReadType_dictText'
          // },
          {
            title:'用水状态',
            align:"center",
            dataIndex: 'waterUsedType_dictText'
          },
          {
            title:'抄表员',
            align:"center",
            dataIndex: 'readerId_dictText'
          },
          {
            title:'录入方式',
            align:"center",
            dataIndex: 'waterReadInput_dictText'
          },
          {
            title:'时间',
            align:"center",
            dataIndex: 'readTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/mr/mrRecords/changeList",
          audit: "/mr/mrRecords/auditsBatch",          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
     
    },
    methods: {
      handleAudit(){
        if(this.selectedRowKeys.length >0 ){
            var ids = "";
            for (var a = 0; a < this.selectedRowKeys.length; a++) {
              ids += this.selectedRowKeys[a] + ",";
            }

          if( this.queryParam.isPassed != null ){
            // 封装查询条件
            let formData = {         
              "ids": ids,
              "isPass": this.queryParam.isPassed,
              "note": this.queryParam.note
            }
            this.auditSubmit(formData);    
          }else{
            this.$message.warning("请选择审核状态!")
          }
        }else{
          this.$message.warning("请选择!")
        }
      },
      /*提交数据 */
      auditSubmit(formData, loading = false) {
        if (loading) {
          this.loading = true
        }
        // 调用接口
        this.loading = true
        postAction(this.url.audit, formData).then(res => {
          if (res.success) {  
            this.$message.success("审核成功!")
          } else {
            this.$error({title: '审核失败', content: res.message})
          }
        }).finally(() => {
          // 这里是无论成功或失败都会执行的方法，在这里关闭loading
          this.loading = false
        }) 
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'sel_search',value:'bookId',text:'抄表本',dictTable:'mws_t_mr_books', dictText:'name', dictCode:'id'})
        fieldList.push({type:'string',value:'readMonth',text:'月份',dictCode:''})
        fieldList.push({type:'sel_search',value:'customerId',text:'户号',dictTable:'mws_t_arc_customers', dictText:'code', dictCode:'id'})
        fieldList.push({type:'popup',value:'cusName',text:'户名', popup:{code:'arc_customer',field:'id',orgFields:'id',destFields:'customer_id'}})
        fieldList.push({type:'BigDecimal',value:'beginScale',text:'起度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'endScale',text:'止度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'amount',text:'用量',dictCode:''})
        fieldList.push({type:'string',value:'waterReadType',text:'抄表周期',dictCode:'water_read_type'})
        fieldList.push({type:'string',value:'waterUsedType',text:'用水状态',dictCode:'water_used_type'})
        fieldList.push({type:'sel_user',value:'readerId',text:'抄表员'})
        fieldList.push({type:'string',value:'waterReadInput',text:'录入方式',dictCode:'water_read_input'})
        fieldList.push({type:'datetime',value:'readTime',text:'时间'})
        fieldList.push({type:'string',value:'remark',text:'说明',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>